import axios from 'axios'






// 创建一个 axios 实例
export const url = 'http://localhost:6080'


const ax = axios.create({
    baseURL: 'url',
    timeout: 300000
})

// 请求拦截器
ax.interceptors.request.use(
    config => {
       
        // console.log(token1)
        // 在请求发送之前做一些处理
        // const token = util.cookies.get('token');
        // if (token) {
        //     config.headers['Authorization'] = token;
        // }

        // 此处为测试用死token
        // eslint-disable-next-line no-unused-vars
        const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIxMzQyNzQwODA3MTQwMzU2MDk4Iiwic2NvcGUiOlsicmVhZCJdLCJleHAiOjE2MTY3NTUwNTksInVzZXJJZCI6MTM0Mjc0MDgwNzE0MDM1NjA5OCwiYXV0aG9yaXRpZXMiOlsiUk9MRV9PcGVyYXRvciJdLCJqdGkiOiJlNWU0ZGJlMi05YmIxLTQ2OGYtYWUzMS01NGYxMDkwMDk3MmMiLCJvcmdJZCI6MTM0MjcyNjI0OTg1MTkyODU3OCwiY2xpZW50X2lkIjoiY2xvdWRvZXJfb3BlcmF0aW9uIiwidXNlcm5hbWUiOiIxMzI5NTM1NjkwNyJ9.JjvLLsUImVwPeAeC6lbUyODQNUY-dnGo_2alMX4vFmM'
        config.headers['Cloudoer-Auth'] = 'bearer ' + token
        return config
    },
    error => {
        // 发送失败
        // console.log(error);
        Promise.reject(error)
    }
)


export default ax

export const stringifyScs = (scs) => {
  let s = '';
  if (scs) {
    if ((scs instanceof Array) && scs.length > 0) {
      scs.forEach((item) => {
        for (const i in item) {
          if (s === '') {
            s += i + '(' + item[i] + ')';
          } else {
            s += ',' + i + '(' + item[i] + ')';
          }
        }
      });
    }
    // } else {
    //   for (let i in scs) {
    //     if (s === '') {
    //       s += i + '(' + item[i] + ')';
    //     } else {
    //       s += ',' + i + '(' + item[i] + ')';
    //     }
    //   }
    // }
  }
  return s;
}


export const axLogin = axios.create({
    baseURL: 'url',
    timeout: 300000
})
// 请求拦截器
axLogin.interceptors.request.use((config) => {
    return config // 添加这一行
}, (error) => {
    return Promise.reject(error)
})

// 响应拦截器

export const g = (url, params) => {
    return ax({
        url: url,
        method: 'get',
        headers: {
            'Content-Type': 'application/json'
        },
        params
    })
}

export const p = (url, params) => {
    return ax({
        url: url,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data: params
    })
}

export const d = (url, params) => {
    return ax({
        url: url,
        method: 'delete',
        headers: {
            'Content-Type': 'application/json'
        },
        data: params
    })
}

export const u = (url, params) => {
    return ax({
        url: url,
        method: 'put',
        headers: {
            'Content-Type': 'application/json'
        },
        data: params
    })
}

export const pa = (url, params) => {
    return ax({
        url: url,
        method: 'patch',
        headers: {
            'Content-Type': 'application/json'
        },
        data: params
    })
}

export const op = (url, params) => {
    return ax({
        url: url,
        method: 'options',
        headers: {
            'Content-Type': 'application/json'
        },
        data: params
    })
}

export const up = (url, params) => {
    return ax({
        url: url,
        method: 'post',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: params
    })
}
